#ifndef HTTPHELPER_H
#define HTTPHELPER_H
#include<QNetworkAccessManager>
#include <QNetworkReply>
#include<QNetworkRequest>
#include<memory>
#include<QObject>
#include<QVector>
#include<QVariantMap>
#include<map>

//登陆状态
enum REQUESTTYPE
{
    REGISTER = 1,
    LOGIN,
    LOGINOUT,
    MEDIALIST,
    ADDMEDIA,
    EDITMEDIA,
    REMOVEMEDIA,
};

class HttpHelper : public QObject
{
    Q_OBJECT    
public:
    static HttpHelper* instance();
    ~HttpHelper();
signals:

    void sig_Operator(const REQUESTTYPE type,bool result);
    void sig_MediaInfo(const QVector<QVariantMap> mediainfo);
public slots:
    void slot_GetmediaInfo();
    void slot_Register(const QVariantMap& infomap);
    void slot_Login(const QVariantMap& infomap);
    void slot_LoginOut(const QVariantMap& infomap);
    void slot_AddmediaInfo(const QVariantMap& infomap);
    void slot_EditmediaInfo(const QVariantMap& infomap);
    void slot_RemovemediaInfo(const QVariantMap& infomap);
protected:
    void HandleReply(const QByteArray& data);
    void onReplyFinished(QNetworkReply* reply);
    void sendGetRequest(const QNetworkRequest& request);
    void sendPostRequest(QNetworkRequest& request,const QByteArray& data);
    void sendRequest(const REQUESTTYPE type,bool isPost,const QByteArray data = QByteArray());
private:
    explicit HttpHelper(QObject *parent = nullptr);
    HttpHelper(const HttpHelper&) = delete;
    HttpHelper& operator = (const HttpHelper&) = delete;
private:
    QString token;
    static std::unique_ptr<HttpHelper> instance_;
    QNetworkAccessManager* networkManager = nullptr;
    std::map<REQUESTTYPE,QString> requestAddrs;
signals:

};

#endif // HTTPHELPER_H
